import Vue from 'vue'

import modal from './modal'
const Modal = Vue.extend(modal)
let instance

const modalInstance = (opt = {}) => {
  if (!instance) {
    instance = new Modal({
      el: document.createElement('div')
    })
  }
  if (instance.show) return
  instance.title = opt.title || instance.title
  instance.content = opt.content || instance.content
  instance.confirm = opt.confirm || instance.confirm
  instance.onConfirm = opt.onConfirm || instance.onConfirm
  document.body.appendChild(instance.$el)
  Vue.nextTick(() => {
    instance.show = true
  })
}

export default modalInstance
